//
//  HXAddressManager.m
//  HXProvincialCitiesCountiesPickerview
//  github:https://github.com/huangxuan518 博客：blog.libuqing.com
//  Created by 黄轩 on 16/7/8.
//  Copyright © 2016年 黄轩. All rights reserved.
//

#import "HXAddressManager.h"

@interface HXAddressManager ()

@end

@implementation HXAddressManager

+ (instancetype)shareInstance {
    static HXAddressManager *_addressManager = nil;
    static dispatch_once_t oncePredicate;
    dispatch_once(&oncePredicate, ^{
        _addressManager = [[self alloc] init];
    });
    return _addressManager;
}

- (NSArray *)provinceDicAry {
    if (!_provinceDicAry) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"address2018" ofType:@"plist"];
        _provinceDicAry = [[NSArray alloc] initWithContentsOfFile:path];
        
        //-------------2017重新组装------
        /*
        NSString *path2 = [[NSBundle mainBundle] pathForResource:@"address2017" ofType:@"plist"];
        NSDictionary *rootTemp = [[NSDictionary alloc] initWithContentsOfFile:path2];
        NSMutableArray *roots = [[NSMutableArray alloc]initWithCapacity:0];
       
        for(NSString *key in rootTemp){
            id province=[rootTemp objectForKey:key][0];
            NSMutableArray *cities = [[NSMutableArray alloc]initWithCapacity:0];
            for(NSString *citykey in province){
                NSMutableArray *areas = [[NSMutableArray alloc]initWithCapacity:0];
                for(NSString *county in [province objectForKey:citykey]){
                    [areas addObject:county];
                }
                NSMutableDictionary *city=[[NSMutableDictionary alloc]initWithCapacity:0];
                [city setObject:citykey forKey:@"city"];
                [city setObject:areas forKey:@"areas"];
                [cities addObject:city];
            }
           NSMutableDictionary *state=[[NSMutableDictionary alloc]initWithCapacity:0];
            [state setObject:key forKey:@"state"];
            [state setObject:cities forKey:@"cities"];
            [roots addObject:state];
        }
        _provinceDicAry = roots;
         */
       //-------------2017重新组装------
        //-------------2017重新组装------
        NSString *path2 = [[NSBundle mainBundle] pathForResource:@"address2017" ofType:@"plist"];
        NSDictionary *rootTemp = [[NSDictionary alloc] initWithContentsOfFile:path2];
        NSMutableArray *roots = [[NSMutableArray alloc]initWithCapacity:0];
        
        
        for(NSString *key in rootTemp){
            id province=[rootTemp objectForKey:key][0];
            NSMutableArray *cities = [[NSMutableArray alloc]initWithCapacity:0];
            for(NSString *citykey in province){
                NSMutableArray *areas = [[NSMutableArray alloc]initWithCapacity:0];
                for(NSString *county in [province objectForKey:citykey]){
                    [areas addObject:county];
                }
                NSMutableDictionary *city=[[NSMutableDictionary alloc]initWithCapacity:0];
                [city setObject:citykey forKey:@"city"];
                [city setObject:areas forKey:@"areas"];
                [cities addObject:city];
            }
            NSMutableDictionary *state=[[NSMutableDictionary alloc]initWithCapacity:0];
            [state setObject:key forKey:@"state"];
            [state setObject:cities forKey:@"cities"];
            [roots addObject:state];
        }
        _provinceDicAry = roots;
        //-------------2017重新组装------
        
    }
    return _provinceDicAry;
}

@end
